import logging
import os
from logging.handlers import RotatingFileHandler


def get_log(log_name):
    log_path = os.path.join(os.path.realpath(os.path.dirname("__file__")), "logs")
    log_file_path = os.path.join(log_path, f"{log_name}.log")
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    logging.basicConfig(level=logging.INFO)
    file_log_handler = RotatingFileHandler(
        log_file_path, maxBytes=1024 * 1024 * 100, backupCount=10
    )
    formatter = logging.Formatter(
        "[%(asctime)s] - [%(levelname)s] - log_msg: %(message)s"
    )
    file_log_handler.setFormatter(formatter)
    script_log = logging.getLogger()
    script_log.addHandler(file_log_handler)
    return script_log
